<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>安全设置</title>
		<link rel="stylesheet" type="text/css" href="__STATIC__/css/tpshop.css" />
		<link rel="stylesheet" type="text/css" href="__STATIC__/css/myaccount.css" />
		<script src="__STATIC__/js/jquery-1.11.3.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body class="bg-f5">
		<include file="user/header"/>
		<div class="home-index-middle">
			<div class="w1224">
				<div class="g-crumbs">
			       	<a href="{:U('User/index')}">我的商城</a>
			       	<i class="litt-xyb"></i>
			       	<span>忘记密码</span>
			    </div>
			    <div class="home-main forgetpaw">
		    		<div class="menumain">
		    			<div class="goodpiece">
							<h1>安全设置</h1>
							<!--<a href=""><span class="co_blue">帮助</span></a>-->
						</div>
			    		<div class="accouun"></div>
			    		<div class="thirset ma-to-20">
			    			<div class="wshef yellc">1.填写用户名<i class="spassw"></i></div>
			    			<div class="wshef">1.验证身份<i class="spassw"></i></div>
			    			<div class="wshef">2.设置新密码<i class="spassw"></i></div>
			    			<div class="wshef">3.完成</div>
			    		</div>
			    		<div class="personerinfro verifyi">
			    			<form action="" method="post" id="forget_pwd">
			    				<ul class="birth_jz">
									<li class="infor_wi_le"><a>账户名：</a></li>
									<li>
										<a>
										<input class="name_zjxs" type="text" name="username" id="username" value="" style="border:1px solid #ccc;" onblur="chkuser()"/>
										</a>
									</li>
								</ul>
								<ul class="name_jz checode">
									<li class="infor_wi_le"><a>验证码：</a></li>
									<li class="teaeu">
										<a>
											<input class="name_zjxs" type="text" name="verify_code" id="captcha" value="">
										</a>
										<a class="ycks" href="javascript:void(0);">
											<img class="yck" style="width:120px" id="captchaImg" alt="captcha" src="{:U('User/verify')}"  onclick="verify()" />
										</a>
									</li>
								</ul>
								<ul class="hobby_jz">
									<li class="infor_wi_le"></li>
									<div class="save_s">
										<input class="save" type="button"  value="下一步" onclick="chkcaptcha()">
									</div>
								</ul>
			    			</form>
			    		</div>
		    		</div>
			    </div>
			</div>
		</div>
        <!--footer-s-->
        <div class="footer p">
            <include file="public/footer" />
        </div>
        <!--footer-e-->
	</body>
	<script type="text/javascript">
	function verify(){
		$('#captchaImg').attr('src','/index.php?m=Home&c=User&a=verify&r='+Math.random());
	}

	var uflag = false;
	var cflag = false;

	function chkuser(){
		var username = $('#username').val();
		if(username == ''){
			show_error('username','账号不能为空');
			return false;
		}else{
			$.ajax({
				url:'/index.php?m=Home&c=User&a=check_username&t='+Math.random(),
				type:'post',
				dataType:'json',
				data:{username:username},
				success:function(t){
					if(t>=1){
						uflag = true;
					}else{
						show_error('username','账号错误');
					}
				}
			})
		}
	}

	function chkcaptcha(){
		var captcha = $('#captcha').val();
		if(captcha == ''){
			show_error('captcha','验证码不能为空');
			return false;
		}else if(captcha.length!=4){
			show_error('captcha','验证码错误');
			return false;
		}else{
			$.ajax({
				url:'/index.php?m=Home&c=User&a=check_captcha&t='+Math.random(),
				type:'post',
				dataType:'json',
				data:{verify_code:captcha},
				success:function(t){
					if(t==1){
						cflag = true;
						gonext();
					}else{
						show_error('captcha','验证码不正确');
						return false;
					}
				}
			})
		}
	}

	function gonext(){
		if($('#username').val() == ''){
			show_error('username','账号不能为空');
			return;
		}
		if($('#captcha').val() == ''){
			show_error('captcha','验证码不能为空');
			return;
		}
		if(!uflag){
			show_error('username','账号验证有误');
			return;
		}else if(!cflag){
			show_error('captcha','图形验证码有误');
			return;
		}
		if(uflag && cflag){
			$('#forget_pwd').submit();
		}
	}

	function show_error(type,msg){
        verify()
		layer.alert(msg, {icon: 2});
		return false;
	}
	</script>
</html>